<template>
  <a-card :bordered="false">
      <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="姓名">
              <a-input placeholder="请输入姓名" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="所属期间">
                <a-month-picker placeholder="请选择所属期间" style="width: 100%" v-model="queryParam.period" @change="onChange"/>
              </a-form-item>
            </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属部门：">
              <j-select-depart :disabled="false" v-model="queryParam.departmentId" />
            </a-form-item>
          </a-col> -->
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属团队">
              <select-team-input  v-model="queryParam.teamId" :tdlx="3" />
            </a-form-item>
          </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="人员状态">
              <j-dict-select-tag
                placeholder="请选择人员状态"
                style="radio"
                v-model="queryParam.employeeStatus"
                dictCode="employee_status"
              />
            </a-form-item>
          </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属岗位">
              <j-dict-select-tag  type="list" v-model="queryParam.mainPost" dictCode="sys_position,name,id,del_flag = 0 and audit_status=2" placeholder="请选择所属岗位"/>
            </a-form-item>
          </a-col> -->
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExport();" :disabled="isDisabledAuth('erpPayrollLedger:export')">导出</a-button>
      <!-- 高级查询区域 -->
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        :customRow="customRow"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <a slot="name" slot-scope="text, record" @click="skip(record.employeeId)">{{ text }}</a>
        <a slot="netPayment" slot-scope="text, record" @click="skipDetil(record.id)">{{ text }}</a>
      </a-table>
    </div>
    <EmployeePayrollManagementTransfer ref="exportMenu" @ok="exportOk"></EmployeePayrollManagementTransfer>
  </a-card>
</template>
<script>
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput';
  import {getAction, httpAction} from '@api/manage'
  import EmployeePayrollManagementTransfer from './EmployeePayrollManagementTransfer'
  import { downFile } from '@/api/manage'
  export default {
    name: 'ErpPayrollLedgerList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      SelectTeamInput,
      EmployeePayrollManagementTransfer
    },
    data () {
      return {
        description: '工资条台账管理页面',
        buttonDisabled: false,
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'姓名',
            align:"center",
            width:200,
            dataIndex: 'name',
            scopedSlots: { customRender: 'name' },
          },
          {
            title:'所属岗位',
            align:"center",
            width:300,
            dataIndex: 'mainPost',
          },
          {
            title:'转正时间',
            align:"center",
            width:200,
            dataIndex: 'probationEndDate',
          },
          {
            title:'所属期间',
            align:"center",
            width:200,
            dataIndex: 'period',
          },
          {
            title:'状态',
            align:"center",
            width:100,
            dataIndex: 'employeeStatus_dictText',
          },
          {
            title:'薪级',
            align:"center",
            width:200,
            sorter: (a, b) => a.payGradeId_dictText - b.payGradeId_dictText,
            dataIndex: 'payGradeId_dictText',
          },
          {
            title:'实发工资（元）',
            align:"center",
            sorter: (a, b) => a.netPayment - b.netPayment,
            dataIndex: 'netPayment',
            scopedSlots: { customRender: 'netPayment' },
          }
        ],
        url: {
          list: "/api/erp/hr/erpPayrollLedger/list",
          exportXlsUrl: "/api/erp/hr/erpPayrollLedger/exportXls",
          importExcelUrl: "api/erp/hr/erpPayrollLedger/importExcel",
          queryEmployeeById: '/api/erp/files/employee/erpEmployeeFile/queryPageById',
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      handleExport(){
        this.$refs.exportMenu.visible = true
        this.$refs.exportMenu.getOptions()
      },
      exportOk(val){
      const fileName = '工资条台账'
      let param = this.getQueryParams()
      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        param['selections'] = this.selectedRowKeys.join(',')
      }
      param.map = val
      console.log('导出参数', param)
      downFile(this.url.exportXlsUrl, param).then(data => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(
            new Blob([data], {
              type: 'application/vnd.ms-excel'
            }),
            fileName + '.xls'
          )
        } else {
          let url = window.URL.createObjectURL(
            new Blob([data], {
              type: 'application/vnd.ms-excel'
            })
          )
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xls')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) // 下载完成移除元素
          window.URL.revokeObjectURL(url) // 释放掉blob对象
        }
      })
    },
      onlyRead() {
        if(!this.buttonDisabled) {
          this.handleExportXls('工资条台账');
        } else {
          this.$message.warning('请勿重复导出！');
          return
        }
        this.buttonDisabled = true
        const that = this
        setTimeout(function() {
          that.buttonDisabled = false // 需要执行的代码
        }, 5000); // 定时时间
      },
      onChange(date, dateString) {
        this.queryParam.period = dateString
      },
      skip(employeeFileId){
        let that=this
      getAction(this.url.queryEmployeeById,{ id: employeeFileId }).then(res => {
        if(res.success){
          let data=res.result.records;
          console.log(data);
          if(data){
            that.$router.push({
              path: '/schedule',
              query: {
                id: employeeFileId,
                applyId: data[0].applyId
              }
            }) 
          }
        }
      })
      },
      skipDetil(id){
        this.$router.push({
          path: `/erp/hr/payrollLedger/ErpPayrollLedgerListDetail/${id}`
        })
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'name',text:'姓名',dictCode:''})
        fieldList.push({type:'string',value:'company',text:'所属公司',dictCode:''})
        fieldList.push({type:'string',value:'departmentId',text:'所属部门',dictCode:''})
        fieldList.push({type:'string',value:'teamId',text:'所属团队',dictCode:''})
        fieldList.push({type:'string',value:'mainPost',text:'所属岗位',dictCode:''})
        fieldList.push({type:'string',value:'probationEndDate',text:'转正时间',dictCode:''})
        fieldList.push({type:'string',value:'period',text:'所属期间',dictCode:''})
        fieldList.push({type:'string',value:'employeeStatus',text:'状态',dictCode:''})
        fieldList.push({type:'string',value:'payGradeId',text:'薪级',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'netPayment',text:'实发工资（元）',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
